// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Cluster
{
	public sealed class ClusterPutSettingsRequestParameters : RequestParameters<ClusterPutSettingsRequestParameters>
	{
		[JsonIgnore]
		public bool? FlatSettings { get => Q<bool?>("flat_settings"); set => Q("flat_settings", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("master_timeout"); set => Q("master_timeout", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("timeout"); set => Q("timeout", value); }
	}

	public sealed partial class ClusterPutSettingsRequest : PlainRequestBase<ClusterPutSettingsRequestParameters>
	{
		internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterPutSettings;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public bool? FlatSettings { get => Q<bool?>("flat_settings"); set => Q("flat_settings", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("master_timeout"); set => Q("master_timeout", value); }

		[JsonIgnore]
		public Elastic.Clients.Elasticsearch.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Duration?>("timeout"); set => Q("timeout", value); }

		[JsonInclude]
		[JsonPropertyName("persistent")]
		public Dictionary<string, object>? Persistent { get; set; }

		[JsonInclude]
		[JsonPropertyName("transient")]
		public Dictionary<string, object>? Transient { get; set; }
	}

	public sealed partial class ClusterPutSettingsRequestDescriptor : RequestDescriptorBase<ClusterPutSettingsRequestDescriptor, ClusterPutSettingsRequestParameters>
	{
		internal ClusterPutSettingsRequestDescriptor(Action<ClusterPutSettingsRequestDescriptor> configure) => configure.Invoke(this);
		public ClusterPutSettingsRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterPutSettings;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public ClusterPutSettingsRequestDescriptor FlatSettings(bool? flatSettings = true) => Qs("flat_settings", flatSettings);
		public ClusterPutSettingsRequestDescriptor MasterTimeout(Elastic.Clients.Elasticsearch.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
		public ClusterPutSettingsRequestDescriptor Timeout(Elastic.Clients.Elasticsearch.Duration? timeout) => Qs("timeout", timeout);
		private Dictionary<string, object>? PersistentValue { get; set; }

		private Dictionary<string, object>? TransientValue { get; set; }

		public ClusterPutSettingsRequestDescriptor Persistent(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			PersistentValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		public ClusterPutSettingsRequestDescriptor Transient(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
		{
			TransientValue = selector?.Invoke(new FluentDictionary<string, object>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (PersistentValue is not null)
			{
				writer.WritePropertyName("persistent");
				JsonSerializer.Serialize(writer, PersistentValue, options);
			}

			if (TransientValue is not null)
			{
				writer.WritePropertyName("transient");
				JsonSerializer.Serialize(writer, TransientValue, options);
			}

			writer.WriteEndObject();
		}
	}
}